﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using SS.LNDX.Service.Core.Model;
using SS.LNDX.Service.Core.Provider;
using Dapper;
using System.Data.SqlClient;
using SiteServer.Plugin;

namespace SS.LNDX.Service.Controllers
{
    [RoutePrefix("site")]
    public class SiteController : ApiController
    {
        public static SqlConnection conn => new SqlConnection(Context.ConnectionString);

        [HttpGet, Route("")]
        public IHttpActionResult List()
        {
            var request = Context.GetCurrentRequest();
            string parentId = request.GetQueryString("parentId");
            string sql = $"SELECT Id, SiteName, SiteDir, TableName FROM siteserver_Site WHERE Id = {parentId} OR ParentId = {parentId}";
            return Ok(conn.Query<dynamic>(sql));
        }
    }
}
